fun main() {
    val node = createNodes()
    println(node)
    println(reverse(node))
}


data class Node(var value: Int, var next: Node?)


fun createNodes(): Node {

    val node5 = Node(5, null)

    val node4 = Node(4, node5)

    val node3 = Node(3, node4)

    val node2 = Node(2, node3)

    return Node(1, node2)
}

fun reverse(head: Node):Node? {

    var prev: Node? = null

    var curr: Node? = head



    while (curr != null) {

        val next: Node? = curr.next

        curr.next = prev

        prev = curr

        curr = next

    }
    return prev

}



